package com.corewillsoft.fireflies.util;

import java.util.ArrayList;
import java.util.List;

public class TypesConverter {

	private TypesConverter() {
	}

	public static int[] stringToIntArray(String string) {
		String[] stringsArray = string.split(",");
		int[] result = new int[stringsArray.length];
		for (int i = 0; i < stringsArray.length; i++) {
			result[i] = Integer.valueOf(stringsArray[i]);
		}

		return result;
	}

	public static List<Integer> stringToIntegerList(String string) {
		String[] stringsArray = string.split(",");
		List<Integer> result = new ArrayList<Integer>(stringsArray.length);
		for (String stringsArrayElement : stringsArray) {
			if (stringsArrayElement.length() > 0) {
				result.add(Integer.valueOf(stringsArrayElement));
			}
		}

		return result;
	}

	public static List<Float> stringToFloatList(String string) {
		String[] stringsArray = string.split(",");
		List<Float> result = new ArrayList<Float>(stringsArray.length);
		for (String stringsArrayElement : stringsArray) {
			result.add(Float.valueOf(stringsArrayElement));
		}

		return result;
	}

	public static List<Boolean> stringToBooleanList(String string) {
		String[] stringsArray = string.split(",");
		List<Boolean> result = new ArrayList<Boolean>(stringsArray.length);
		for (String stringsArrayElement : stringsArray) {
			result.add(Boolean.valueOf(stringsArrayElement));
		}

		return result;
	}
	
	public static int bool2int(boolean val) {
		return val ? 1 : 0;
	}

	public static boolean int2bool(int val) {
		return val != 0;
	}
}
